package generadorDescriptores.database;

public class ConnectionData {
	private String ip;
	private String puerto;
	private String driver;
	private String usuario; 
	private String password;
	private String connectionUrl; 
	private String db; 
	
	public void setIp(String ip) {
		this.ip = ip;
	}

	public void setPuerto(String puerto) {
		this.puerto = puerto;
	}

	public void setDriver(String driver) {
		this.driver = this.findDriver(driver);
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

	public void setPassword(String pass) {
		this.password = pass;
	}
	
	public void setDb(String dbName){
		this.db = dbName;
	}

	private String buildConnectionUrl() {
		StringBuffer url = new StringBuffer();
		url.append("jdbc:mysql://");
		url.append(ip);
		url.append(":"+ puerto +"/");
		url.append(db);
		
		return url.toString();
	}
	
	public String getUrlConnection(){
		return this.buildConnectionUrl();
	}
	

	private String findDriver(String driver){
		if(driver.equals("MySQL Driver")){
			return Drivers.getDriverMySQL();			
		}
		else{
			/*TODO faltaria la implementacion para el resto de los drivers */
			return null;
		}
	}

	public String getIp() {
		return ip;
	}

	public String getPuerto() {
		return puerto;
	}

	public String getDriver() {
		return driver;
	}

	public String getUsuario() {
		return usuario;
	}

	public String getPassword() {
		return password;
	}

	public String getDb() {
		return db;
	}
	
	
	
	public boolean equals(ConnectionData data){
		if(data.getIp().equals(this.ip) && data.getDb().equals(this.db) && data.getDriver().equals(this.driver) && data.getPassword().equals(this.password) && data.getPuerto().equals(this.puerto) && data.getUsuario().equals(this.usuario)){
			return true;
		}
		else		
			return false;
	}
	
	
	
	
	

}
